home *** CD-ROM | disk | FTP | other *** search
/ Aminet 21 / Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso / Aminet / gfx / show / gs_src_gs.lha / gs5.03 / ivmspace.h < prev    next >
C/C++ Source or Header  |  1997-04-28  |  5KB  |  105 lines

  1. /* Copyright (C) 1992, 1993, 1994, 1996, 1997 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of Aladdin Ghostscript.
  4.   
  5.   Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  6.   or distributor accepts any responsibility for the consequences of using it,
  7.   or for whether it serves any particular purpose or works at all, unless he
  8.   or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  9.   License (the "License") for full details.
  10.   
  11.   Every copy of Aladdin Ghostscript must include a copy of the License,
  12.   normally in a plain ASCII text file named PUBLIC.  The License grants you
  13.   the right to copy, modify and redistribute Aladdin Ghostscript, but only
  14.   under certain conditions described in the License.  Among other things, the
  15.   License requires that the copyright notice and this notice be preserved on
  16.   all copies.
  17. */
  18.  
  19. /* ivmspace.h */
  20. /* Local/global space management */
  21. /* Requires iref.h */
  22.  
  23. #ifndef ivmspace_INCLUDED
  24. #  define ivmspace_INCLUDED
  25.  
  26. #include "gsgc.h"
  27.  
  28. /*
  29.  * r_space_bits and r_space_shift, which define the bits in a ref
  30.  * that carry VM space information, are defined in iref.h.
  31.  * r_space_bits must be at least 2.
  32.  */
  33. #define a_space (((1 << r_space_bits) - 1) << r_space_shift)
  34. /*
  35.  * The i_vm_xxx values are defined in gsgc.h.
  36.  */
  37. typedef enum {
  38.     avm_foreign = (i_vm_foreign << r_space_shift),
  39.     avm_system = (i_vm_system << r_space_shift),
  40.     avm_global = (i_vm_global << r_space_shift),
  41.     avm_local = (i_vm_local << r_space_shift),
  42.     avm_max = avm_local
  43. } avm_space;
  44. #define r_space(rp) (avm_space)(r_type_attrs(rp) & a_space)
  45. #define r_space_index(rp) ((int)r_space(rp) >> r_space_shift)
  46. #define r_set_space(rp,space) r_store_attrs(rp, a_space, (uint)space)
  47.  
  48. /*
  49.  * According to the PostScript language specification, attempting to store
  50.  * a reference to a local object into a global object must produce an
  51.  * invalidaccess error.  However, systemdict must be able to refer to
  52.  * a number of local dictionaries such as userdict and errordict.
  53.  * Therefore, we implement a special hack in 'def' that allows such stores
  54.  * if the dictionary being stored into is systemdict (which is normally
  55.  * only writable during initialization) or a dictionary that appears
  56.  * in systemdict (such as level2dict), and the current save level is zero
  57.  * (to guarantee that we can't get dangling pointers).
  58.  * We could allow this for any global dictionary, except that the garbage
  59.  * collector must treat any such dictionaries as roots when collecting
  60.  * local VM without collecting global VM.
  61.  * We make a similar exception for .makeglobaloperator; this requires
  62.  * treating the operator table as a GC root as well.
  63.  *
  64.  * We extend the local-into-global store check because we have four VM
  65.  * spaces (local, global, system, and foreign), and we allow PostScript
  66.  * programs to create objects in any of the first three.  If we define
  67.  * the "generation" of an object as foreign = 0, system = 1, global = 2,
  68.  * and local = 3, then a store is legal iff the generation of the object
  69.  * into which a pointer is being stored is greater than or equal to
  70.  * the generation of the object into which the store is occurring.
  71.  *
  72.  * We must check for local-into-global stores in three categories of places:
  73.  *
  74.  *    - The scanner, when it encounters a //name inside {}.
  75.  *
  76.  *    - All operators that allocate ref-containing objects and also
  77.  *    store into them:
  78.  *        packedarray  gstate  makepattern?
  79.  *        makefont  scalefont  definefont  filter
  80.  *
  81.  *    - All operators that store refs into existing objects
  82.  *    ("operators" marked with * are actually PostScript procedures):
  83.  *        put(array)  putinterval(array)  astore  copy(to array)
  84.  *        def  store*  put(dict)  copy(dict)
  85.  *        dictstack  execstack  .make(global)operator
  86.  *        currentgstate  defineusername
  87.  */
  88.  
  89. /* Test whether an object is in local space, */
  90. /* which implies that we need not check when storing into it. */
  91. #define r_is_local(rp) (r_space(rp) == avm_local)
  92. /* Test whether an object is foreign, i.e., outside known space. */
  93. #define r_is_foreign(rp) (r_space(rp) == avm_foreign)
  94. /* Check whether a store is allowed. */
  95. #define store_check_space(destspace,rpnew)\
  96.   if ( r_space(rpnew) > (destspace) )\
  97.     return_error(e_invalidaccess)
  98. #define store_check_dest(rpdest,rpnew)\
  99.   store_check_space(r_space(rpdest), rpnew)
  100. /* BACKWARD COMPATIBILITY (not used by any Ghostscript code per se) */
  101. #define check_store_space(rdest,rnewcont)\
  102.   store_check_dest(&(rdest),&(rnewcont))
  103.  
  104. #endif                    /* ivmspace_INCLUDED */
  105.